package Main;

import plugin.LibsThread;
import plugin.SystemClassLoader;
import system.Logging;
import system.MessageOUTPUT;
import system.ReadSettings;
import system.getTimeDate;

/**
 * IDDS - is a next generation software for massive file and message delivery.
 * All rights reserved.
 *
 * @author ZeM
 */
public class Main {

    public static void main(String[] args) {
        //getting start time;
        Parameters.IDDSStartTime = new getTimeDate().getTimeDate("yyyyMMddHHmmss");

        //if program was launched with parameter -h or --help
        if (args.length > 0) {
            if (args[0].equals("-h") | args[0].equals("--help")) {
                //reading settings
                new ReadSettings();
                //showing help
                new SystemClassLoader().Load("iddsHELP.jar");
            } else if (args[0].equals("--windows")) { //if program lounched in Windows

                Parameters.LounchedFromWindows = true;
                if (args.length > 1) {
                    if (args[1].equals("--GUI")) {
                        //start GUI
                        LibsThread lt=new LibsThread();
            lt.lib_name="iddsGUI";
            new Thread(lt).start();
                        

                    }
                }
                //start
                new StartIDDS();

            } else if (args[0].equals("--GUI")) {
                //start GUI
                LibsThread lt=new LibsThread();
            lt.lib_name="iddsGUI";
            new Thread(lt).start();
            }
        } else if (args.length < 1) {//if program was lounched without any parameter

            new StartIDDS();
        }

        new MessageOUTPUT().OUTPUT("s0003",null);
        //stoping all loaded plugins

        for (int i = 0; i < Parameters.LoadedPluginNames.length; i++) {
            if (Parameters.LoadedPluginNames[i] != null) {
                Parameters.LoadedPlugins[i].Stop();
            }

        }
        //close log
        new Logging().AddEvent("System shutdown");
        new Logging().Close();
        System.exit(0);


    }
}
